package hu.stud.uszeged.inf.prf.prftrac.session.dao;


import hu.stud.uszeged.inf.prf.prftrac.entity.Event;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

@Name("eventDao")
public class EventDao {

	@In
	private EntityManager entityManager;
	
	public List<Event> getEventsOrderedByDate() {
		String queryString = "from Event e ordered by e.dateTime desc";
    	Query q = entityManager.createQuery(queryString);
    	return (List<Event>)q.getResultList();
	}
	
	public List<Event> getEventsByDate(Date date) {
		String queryString = "from Event e where e.dateTime = :dt";
    	Query q = entityManager.createQuery(queryString);
    	q.setParameter("dt", date);
    	return (List<Event>)q.getResultList();
	}
	
	public List<Date> getDistinctDates() {
		String queryString = "select distinct e.dateTime from Event e";
    	Query q = entityManager.createQuery(queryString);
    	return (List<Date>)q.getResultList();
	}
}
